package cn.iocoder.yudao.module.promotion.dal.mysql.prizedraw;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.prizedraw.vo.PrizeDrawPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.prizedraw.vo.PrizeDrawRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.prizedraw.vo.PrizeDrawSaveReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.prizedraw.vo.PrizeDrawStoreRespVo;
import cn.iocoder.yudao.module.promotion.dal.dataobject.prizedraw.PrizeDrawDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 抽奖活动 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PrizeDrawMapper extends BaseMapperX<PrizeDrawDO> {

    default PageResult<PrizeDrawDO> selectPage(PrizeDrawPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PrizeDrawDO>()
                .likeIfPresent(PrizeDrawDO::getPrizeDrawName, reqVO.getPrizeDrawName())
                .eqIfPresent(PrizeDrawDO::getPrizeDrawBegin, reqVO.getPrizeDrawBegin())
                .eqIfPresent(PrizeDrawDO::getPrizeDrawEnd, reqVO.getPrizeDrawEnd())
                .eqIfPresent(PrizeDrawDO::getPrizeDrawRule, reqVO.getPrizeDrawRule())
                .eqIfPresent(PrizeDrawDO::getPrizeDrawBackground, reqVO.getPrizeDrawBackground())
                .eqIfPresent(PrizeDrawDO::getPrizeDrawTurntable, reqVO.getPrizeDrawTurntable())
                .eqIfPresent(PrizeDrawDO::getTodayTotalType, reqVO.getTodayTotalType())
                .eqIfPresent(PrizeDrawDO::getTodayTotalNums, reqVO.getTodayTotalNums())
                .eqIfPresent(PrizeDrawDO::getKindExchangeType, reqVO.getKindExchangeType())
                .eqIfPresent(PrizeDrawDO::getKindExchangeNums, reqVO.getKindExchangeNums())
                .eqIfPresent(PrizeDrawDO::getUpdown, reqVO.getUpdown())
                .betweenIfPresent(PrizeDrawDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PrizeDrawDO::getPrizeDrawId));
    }

    /**
     * 抽奖活动库存
     *
     * @param prizeDrawId 抽奖活动ID
     * @return 抽奖活动库存
     */
    List<PrizeDrawStoreRespVo> getStore(@Param("prizeDrawId") Long prizeDrawId);

    /**
     * 获得抽奖活动分页
     * @param reqVO
     * @return
     */
    PageResult<PrizeDrawRespVO> getPrizeDrawPage(@Param("reqVO") PrizeDrawPageReqVO reqVO);

    /**
     * 获得抽奖活动
     * @param id
     * @return
     */
    PrizeDrawRespVO single(@Param("id") Long id);

    /**
     * 获取当前启用的进行中 抽奖活动
     *
     * @return
     */
    PrizeDrawRespVO getCurrentPrizeDrawActivity();

    /**
     * 取时间交集判定是否有重复
     *
     * @param reqVO 抽奖活动信息
     * @return 交集数量
     */
    Long intersection(@Param("reqVO") PrizeDrawSaveReqVO reqVO);

    /**
     * 取时间交集判定是否有重复
     *
     * @param prizeDrawDO 抽奖活动信息
     * @return 交集数量
     */
    PrizeDrawRespVO intersectionVo(@Param("prizeDrawDO") PrizeDrawDO prizeDrawDO);

    /**
     *
     * @return
     */
    PrizeDrawRespVO getRecentlyPrizeDraw();
}